package com.example.administrator.yanfoxconn.adapter;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.yanfoxconn.R;
import com.example.administrator.yanfoxconn.activity.GoodsIntelligenceActivity;
import com.example.administrator.yanfoxconn.activity.KKCHeckListActivity;
import com.example.administrator.yanfoxconn.bean.GoodsMessage;
import com.example.administrator.yanfoxconn.bean.KKGWMessage;

import java.util.List;


/**
 * 智慧物品列表 的 適配器
 * Created by wangqian on 2019/6/28.
 */

public class KKCheckListAdapter extends BaseAdapter {

    private KKCHeckListActivity activity;
    private List<KKGWMessage> lists;

    private OnClickListener onClickListener;

    public KKCheckListAdapter(KKCHeckListActivity activity, List<KKGWMessage> lists) {

        this.activity = activity;
        this.lists = lists;
    }

    @Override
    public int getCount() {
        Log.e("--------","lists.size()==="+lists.size());
        return lists.size();
    }

    @Override
    public Object getItem(int i) {
        return lists.get(i);
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        int num = position +1;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_kk_check_list, null);

//            holder.tvNo = convertView.findViewById(R.id.tv_list_no);
//            holder.tvName = convertView.findViewById(R.id.tv_list_name);
//            holder.tvMac = convertView.findViewById(R.id.tv_list_mac);
//            holder.tvSn = convertView.findViewById(R.id.tv_list_sn);
//            holder.tvXian = convertView.findViewById(R.id.tv_list_xian);
//            holder.tvPin = convertView.findViewById(R.id.tv_list_pin);
//            holder.tvCol = convertView.findViewById(R.id.tv_list_col);
//            holder.tvNum = convertView.findViewById(R.id.tv_list_num);

            holder.tvNo = convertView.findViewById(R.id.tv_custom_no);
            holder.tvName = convertView.findViewById(R.id.tv_fee_code);
            holder.tvYJ = convertView.findViewById(R.id.tv_yj);
            holder.tvWJ = convertView.findViewById(R.id.tv_wj);
            holder.tvYC = convertView.findViewById(R.id.tv_yc);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvNo.setText(lists.get(position).getCUSTOMSCODE());
        holder.tvName.setText(lists.get(position).getFEECODE());
        if (lists.get(position).getYJ().equals("")){
            holder.tvYJ.setText("0");
        }else{
        holder.tvYJ.setText(lists.get(position).getYJ() );
        }
        if (lists.get(position).getWJ().equals("")){
            holder.tvWJ.setText("0");
        }else{
        holder.tvWJ.setText(lists.get(position).getWJ());
        }
        if (lists.get(position).getYC().equals("")){
            holder.tvYC.setText("0");
        }else{
        holder.tvYC.setText(lists.get(position).getYC());
        }
        holder.tvYJ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener != null) {
                    onClickListener.OnClickListenerYJ(position,"YJ");
                }
            }
        });
        holder.tvWJ.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener != null) {
                    onClickListener.OnClickListenerWJ(position,"WJ");
                }
            }
        });
        holder.tvYC.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onClickListener != null) {
                    onClickListener.OnClickListenerYC(position,"YC");
                }
            }
        });

        return convertView;
    }

    private class ViewHolder {
//        public TextView tvNo, tvName, tvMac, tvSn,tvXian, tvPin, tvCol, tvNum;//編號,名稱,MAC,SN,顯卡,品牌,顏色,數量单位
        public TextView tvNo, tvName, tvYJ, tvWJ,tvYC;//編號,品名，規格型號，數量單位，品牌
    }
    public interface OnClickListener {
        void OnClickListenerYJ(int position,String flag);
        void OnClickListenerWJ(int position,String flag);
        void OnClickListenerYC(int position,String flag);
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

}
